/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yudisium;

import database.OraConnection;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Win-7
 */
public class PengendaliPemeriksaanYudisium {

    public static void lihatTabelYudisium(KelasSekretariat se) {
        PengendaliPendaftaranYudisium.DAFTAR_MAHASISWA = new ArrayList<Mahasiswa>();
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl", "MHS115314033", "MHS115314033");
        java.sql.Statement statement = null;
        try {
            statement = conn.createStatement();
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliPemeriksaanYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
        String sqQ = "select * from yudisium where periode_bulan = '" + se.getBulan() + "' and (periode_tanggal >= " + se.getTanggal_awal() + " and periode_tanggal <= " + se.getTanggal_akhir() + ")";
        ResultSet result = null;
        try {
            result = statement.executeQuery(sqQ);
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliPemeriksaanYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            while (result.next()) {
                Mahasiswa temp = new Mahasiswa();
                temp.setNama(result.getString("nama"));
                temp.setNim(result.getString("nim"));
                temp.setNope(result.getString("nomor_hp"));
                temp.setProdi(result.getString("prodi"));

                temp.setPeriode(result.getString("periode_bulan"));

                temp.setTanggal(result.getString("periode_tanggal"));

                temp.setBebaspinjamLab(result.getString("bebaspinjam_lab"));
                temp.setBebaspinjamDosen(result.getString("bebaspinjam_dosen"));
                temp.setLaporanKP(result.getString("laporan_kp"));

                PengendaliPendaftaranYudisium.DAFTAR_MAHASISWA.add(temp);
            }
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliPemeriksaanYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
        try {
            conn.close();
        } catch (SQLException ex) {
        }
    }

    public static void ubahDataYudisium(Mahasiswa yudisium) {
        Connection conn = OraConnection.open("jdbc:oracle:thin:@172.23.9.185:1521:orcl", "MHS115314033", "MHS115314033");
        Statement statement = null;
        try {
            statement = conn.createStatement();
            String sql = "update yudisium set bebaspinjam_lab='" + yudisium.getBebaspinjamLab()
                    + "',bebaspinjam_dosen='" + yudisium.getBebaspinjamDosen()
                    + "',bukti_kp='" + yudisium.getLaporanKP()
                    + " where nim='" + yudisium.getNim() + "'";
            statement.executeUpdate(sql);
            conn.close();
        } catch (SQLException ex) {
            Logger.getLogger(PengendaliPendaftaranYudisium.class.getName()).log(Level.SEVERE, null, ex);
        }
        JOptionPane.showMessageDialog(null, "Berhasil di update");
    }
}
